<?php

      // header("Content-Type: application/json");
       
        
       
       $begin=$_GET['begin'];
       $end=$_GET['end'];
  /*     
       
       $begin=1964;
       $end=2014;
      */ 
 
       
        
       $fd=  fopen("archivos/datosInvIFC.txt", "w");
        //Se almacena la conexion en la variable $con
        
        $con=mysqli_connect("192.168.1.10","srojas","anemona") or die("Failed to connect with database!!!!");
        mysqli_select_db( $con,"hermes2"); 
        
        
        $sth = mysqli_query($con,"select anio,total from titular_assoc where anio>=$begin and anio<=$end");
       
        //}
        mysqli_close($con);

        
       
        $rows = array();
        $table = array();
        $table['cols'] = array(

        // Labels for your chart, these represent the column titles
        // Note that one column is in "string" format and another one is in "number" format as pie chart only required "numbers" for calculating percentage and string will be used for column title
        array('label' => 'anio', 'type' => 'string'),
        array('label' => 'total', 'type' => 'number')

        );
        
        fwrite($fd, "Anio   num_investigadores"."\r\n");
        while($r = mysqli_fetch_assoc($sth)) {
            fwrite($fd,"\t".$r['anio']."\t");
            fwrite($fd, $r['total']."\r\n");
            
        $temp = array();
        // the following line will be used to slice the Pie chart
        $temp[] = array('v' => (string) utf8_encode($r['anio'])); 

        // Values of each slice
        $temp[] = array('v' => (int) $r['total']); 
        $rows[] = array('c' => $temp);
        }

       
        
        
        $table['rows'] = $rows;
        
        fclose($fd);
        
       
        echo json_encode($table);
        
        
        
        ?>
